package com.zhu.ssm.handler;

import com.zhu.ssm.exception.BusinessException;
import com.zhu.ssm.pojo.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class MyExceptionHandler {
    //处理异常
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result doException(Exception e){
        log.error(e.getMessage());
        Result result = new Result();
        result.setCode(-999);
        result.setMessage("未知的异常，提示友好信息EXCEPTION");
        result.setSuccess(false);
        return result;
    }

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result doBusinessException(BusinessException e){
        log.error(e.getMessage());
        Result result = new Result();
        result.setCode(-999);
        result.setMessage("未知的异常，提示友好信息");
        result.setSuccess(false);
        return result;
    }
}
